package com.shuyigou.service;

import com.shuyigou.mapper.BookMapper;
import com.shuyigou.pojo.Book;
import com.shuyigou.util.SqlSessionFactoryUtils;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

public class ProductService {
    public Book selectByISBN(String ISBN) {
        //1、获取sqlSessionFactory对象
        SqlSessionFactory sqlSessionFactory = SqlSessionFactoryUtils.getSqlSessionFactory();
        //2、获取sqlSession
        SqlSession sqlSession = sqlSessionFactory.openSession();
        //3、获取Mapper
        BookMapper mapper = sqlSession.getMapper(BookMapper.class);
        //4、调用方法
        Book book = mapper.selectByISBN(ISBN);
        //5、释放资源
        sqlSession.close();
        return book;
    }

}
